// import sqlite3 from 'sqlite3'
import { Dbo, DbContext, DbMigration } from 'sqlite3-queries'
const NODE_ENV = process.env.NODE_ENV
import path from 'path'
import { app } from 'electron'
let DB_PATH = path.join(app.getAppPath(), '/db/test.db')
if (NODE_ENV !== 'development') {
  DB_PATH = path.join(path.dirname(app.getPath('exe')), '/db/test1.db')
}

class UserContext extends DbContext {
  constructor(fileName: string) {
    const dbo = new Dbo(fileName)
    super(dbo, UserContext.migrations)
  }
  static migrations: DbMigration[] = [
    {
      version: 1,
      sqls: ['CREATE TABLE IF NOT EXISTS users (id STRING PRIMARY KEY, name STRING, password STRING)']
    },
    {
      version: 2,
      sqls: ['CREATE TABLE IF NOT EXISTS tabs (id STRING PRIMARY KEY, name STRING, age1 INT)']
    }
  ]
}

const dbo = new UserContext(DB_PATH)

dbo.open().then((res) => {
  console.log('res', res)
})
